package org.example;

import java.util.Collections;

class Solution {
    private void Swap(int[] arr, int a, int b){
        int tmp = arr[a];
        arr[a] = arr[b];
        arr[b] = tmp;
    }
    public void sortColors(int[] nums) {
        int left = -1, right = nums.length;
        int cur = 0;
        while(cur < right){
            if(nums[cur] == 0) Swap(nums, ++left, cur++);
            else if(nums[cur] == 1) cur++;
            else Swap(nums, --right, cur);
        }
    }
}